# -*- coding: utf-8 -*-
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.api import mail
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template
from google.appengine.api import taskqueue
from google.appengine.ext import deferred
from google.appengine.ext.webapp.util import login_required

from copy import deepcopy
import os, datetime, time, traceback, cgi

from execq import *
from jobcron import *
from taskrun import *
import database
from igaelib import logging
from dbopr import *

class InitHandler(webapp.RequestHandler):

    def get(self):
        template_values = {
                'test'  :   time.strftime('%H%M%S')}
        path = os.path.join(os.path.dirname(__file__), 'templates/init.html')
        self.response.out.write(template.render(path, template_values))


app =  webapp.WSGIApplication([
                (r'/init', InitHandler), 
                (r'/addq', QueueHandler), 
                (r'/queue1', Queue1Worker), 
                (r'/cronweather', CronWeather), 
                (r'/cronclrhis', CronClrHis), 
                (r'/mail',   SendMail),
                (r'/setcet6/(.+)',   SetCet6Word),
                (r'/setcet6term/(.+)',   SetCet6WordTerm),
                (r'/getcet6',   GetCet6Word),
                (r'/tableopr',   TableOpr),
                (r'/notebook',   AddNoteBook),
                (r'/test',   CronWeather),
                ],
                debug=True)
def main():
    util.run_wsgi_app(app)



if __name__ == '__main__':
    #pullq = taskqueue.Queue('pullqueue')
    #deferred.defer(cyclerun)
    main()
